/*
 * Copyright (c)  2008 Sebastien Tremblay
 *
 * id3-tag-builder - classes.db.MusicAlbum.java
 *
 * All source and documentation is copyrighted by Sebastien Tremblay
 * (seb at ryders dot net) and made available under the Apache License 2.0.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * $Id: MusicAlbum.java 33 2010-04-02 07:47:55Z ryders $
 */
package com.empireone.id3tagbuilder.classes.db;

import java.util.ArrayList;

/**
 *
 * @author Sebastien Tremblay
 */
public class MusicAlbum {

    private int discCount;
    private String recordLabel;
    private String coverArt;
    private String artist;
    private int year;
    private String genre;
    private String name;
    private String performer;
    private ArrayList<MusicTrack> tracks;

    /**
     *
     */
    public void inheritTags() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    /**
     * 
     * @param album
     * @return
     */
    public boolean merge(MusicAlbum album) {
        boolean changes = false;

        if (album.getName() != null) {
            changes = changes || !album.getName().equals(getName());
            setName(album.getName());
        }

        if (album.getGenre() != null) {
            changes = changes || !album.getGenre().equals(getGenre());
            setName(album.getGenre());
        }

        if (album.getYear() > 0) {
            changes = changes || album.getYear() != getYear();
            setYear(album.getYear());
        }

        if (album.getRecordLabel() != null) {
            changes = changes || !album.getRecordLabel().equals(getRecordLabel());
            setRecordLabel(album.getRecordLabel());
        }

        if (album.getCoverArt() != null) {
            changes = changes || !album.getCoverArt().equals(getCoverArt());
            setCoverArt(album.getCoverArt());
        }

        if (album.getArtist() != null) {
            changes = changes || !album.getArtist().equals(getArtist());
            setArtist(album.getArtist());
        }

        if (album.getDiscCount() > 0) {
            changes = changes || album.getDiscCount() != getDiscCount();
            setDiscCount(album.getDiscCount());
        }

        for (MusicTrack track : album.getTracks()) {
            track.setMusicAlbum(this);
            addTrack(track);
            changes = true;
        }

        return changes;
    }

    /**
     * @return the discCount
     */
    public int getDiscCount() {
        return discCount;
    }

    /**
     * @param discCount the discCount to set
     */
    public void setDiscCount(int discCount) {
        this.discCount = discCount;
    }

    /**
     * @return the trackCount
     */
    public int getTrackCount() {
        return getTracks().size();
    }

    /**
     * @return the recordLabel
     */
    public String getRecordLabel() {
        return recordLabel;
    }

    /**
     * @param recordLabel the recordLabel to set
     */
    public void setRecordLabel(String recordLabel) {
        this.recordLabel = recordLabel;
    }

    /**
     * @return the artist
     */
    public String getArtist() {
        return artist;
    }

    /**
     * @param artist the artist to set
     */
    public void setArtist(String artist) {
        this.artist = artist;
    }

    /**
     * @return the year
     */
    public int getYear() {
        return year;
    }

    /**
     * @param year the year to set
     */
    public void setYear(int year) {
        this.year = year;
    }

    /**
     * @return the genre
     */
    public String getGenre() {
        return genre;
    }

    /**
     * @param genre the genre to set
     */
    public void setGenre(String genre) {
        this.genre = genre;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the performer
     */
    public String getPerformer() {
        return performer;
    }

    /**
     * @param performer the performer to set
     */
    public void setPerformer(String performer) {
        this.performer = performer;
    }

    /**
     * @return the tracks
     */
    public ArrayList<MusicTrack> getTracks() {
        if (tracks == null) {
            tracks = new ArrayList<MusicTrack>();
        }
        return tracks;
    }

    /**
     * @param track
     */
    public void addTrack(MusicTrack track) {

        this.getTracks().add(track);
    }

    /**
     * @return the coverArt
     */
    public String getCoverArt() {
        return coverArt;
    }

    /**
     * @param coverArt the coverArt to set
     */
    public void setCoverArt(String coverArt) {
        this.coverArt = coverArt;
    }

    @Override
    public String toString() {

        String res = "";

        res += "\n\n\nAlbum: " + name;
        res += "\nArtist: " + artist;
        res += "\nYear: " + year;
        res += "\nDiscs: " + discCount;
        res += "\nLabel: " + recordLabel;
        res += "\nCover: " + coverArt;

        for(MusicTrack t : tracks) {
            res += t.toString();
        }

        return res;
    }
}
